<?php
require("../qcubed.inc.php");
class UserList extends QForm {
    // Local instance of the Meta DataGrid to list Users
    protected $dtgUsers;
    protected $AuthSys;
    // Create QForm Event Handlers as Needed

//		protected function Form_Exit() {}
//		protected function Form_Load() {}
//		protected function Form_PreRender() {}
//		protected function Form_Validate() {}

    protected function Form_Run() {
        // Security check for ALLOW_REMOTE_ADMIN
        $this->AuthSys = new Perm();
        $this->AuthSys->IsAdmin(true);
    }


    protected function Form_Create() {
        // Instantiate the Meta DataGrid
        $this->dtgUsers = new UserDataGrid($this);

        // Style the DataGrid (if desired)
        $this->dtgUsers->CssClass = 'datagrid';
        $this->dtgUsers->AlternateRowStyle->CssClass = 'alternate';

        // Add Pagination (if desired)
        $this->dtgUsers->Paginator = new QPaginator($this->dtgUsers);
        $this->dtgUsers->ItemsPerPage = 20;

        // Use the MetaDataGrid functionality to add Columns for this datagrid

        // Create an Edit Column
        $this->dtgUsers->RowActionParameterHtml = '<?= QS_ENCODE($_ITEM->Id) ?>';
        $this->dtgUsers->AddRowAction(new QClickEvent(), new QAjaxAction('dtgUsers_Click'));
        $this->dtgUsers->AddRowAction(new QMouseOverEvent(), new QCssClassAction('selectedStyle'));
        $this->dtgUsers->AddRowAction(new QMouseOutEvent(), new QCssClassAction());

        // Create the Other Columns (note that you can use strings for user's properties, or you
        // can traverse down QQN::user() to display fields that are down the hierarchy)

        $this->dtgUsers->MetaAddColumn('UserName');
        //$this->dtgUsers->MetaAddColumn('Password');
        $this->dtgUsers->MetaAddColumn('Active');
        $this->dtgUsers->MetaAddColumn(QQN::User()->UserType);

        $this->dtgUsers->MetaAddColumn(QQN::User()->PrimaryRole);

        $this->dtgUsers->MetaAddColumn(QQN::User()->Person);
        $this->dtgUsers->MetaAddColumn('LastLogin');
    }

    protected function dtgUsers_Click($strFormId, $strControlId, $strParameter) {
        $intId = $strParameter;
        $strEditPageUrl =  __SECURITY__. '/user_edit.php/'. $intId;

        QApplication::Redirect($strEditPageUrl);

    }
}
UserList::Run('UserList','tpl/user_list.tpl.php');
?>
